package com.sky.mapper;

import com.sky.annotation.autoFile;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    @autoFile(value = OperationType.INSERT)
    //新增员工
   @Insert("insert into employee(id_number,name,phone,sex,username ,create_time,update_time,status,password,create_user ,update_user) " +
           "values(#{idNumber},#{name},#{phone},#{sex},#{username},#{createTime},#{updateTime},#{status},#{password},#{createUser},#{updateUser})")
    void addEmployee(Employee employee);


   //分页查询员工
    List<Employee> pageQuery(EmployeePageQueryDTO employeePageQuerydto);
    @autoFile(value = OperationType.UPDATE)
    //启用或禁用员工账号
    void update(Employee employee);

    //根据id查询员工
    Employee getById(Long id);

    //修改员工信息

    void updateEmployee(Employee employee);


    @autoFile(value = OperationType.UPDATE)
    @Update("update employee set password = #{password} where id = #{id}")
    //修改密码
    void updatePassword(Employee employee);

    @Select("select count(1) from employee where password = #{password} and id = #{id}")
    Integer countByMap(Employee employee);
}
